#pragma once 
#include <iostream>
#include <fstream> // 包含文件流头文件，用于文件操作
using namespace std;

// 定义激光雷达类
class Lidar {
public:
    string model;  // 型号
    int channels;       // 通道数
    float range;        // 测试范围
    float power;        // 功耗

    // 默认构造函数
    Lidar()
        : model("Unknown"), channels(0), range(0.0f), power(0.0f) {}

    // 构造函数
    Lidar(string m, int ch, float r, float p) : model(m), channels(ch), range(r), power(p) {}

    // 各属性的set方法
    void setModel(string newModel) {
        model = newModel;
    }

    void setChannels(int newChannels) {
        channels = newChannels;
    }

    void setRange(float newRange) {
        range = newRange;
    }

    void setPower(float newPower) {
        power = newPower;
    }

    // 打印多线激光雷达信息
    void print() {
        cout << "多线激光雷达型号: " << model << endl;
        cout << "通道数: " << channels << endl;
        cout << "测试范围: " << range << "m" << endl;
        cout << "功耗: " << power << "W" << endl;
    }

    // 保存多线激光雷达信息到本地文件
    void save(const string &filename) {
        ofstream outFile(filename, ios::app);  // 以追加模式打开文件
        if (!outFile.is_open()) {
            cerr << "无法打开文件 " << filename << endl;
            return;
        }
        outFile << "多线激光雷达型号: " << model << endl;
        outFile << "通道数: " << channels << endl;
        outFile << "测试范围: " << range << "m" << endl;
        outFile << "功耗: " << power << "W" << endl;
        outFile.close();  // 关闭文件流
    }
};